package com.pf.controller;

import com.pf.dto.BaseResult;
import com.pf.dto.PageBaseResp;
import com.pf.dto.request.UserAddReq;
import com.pf.dto.request.UserListReq;
import com.pf.dto.request.UserUpdReq;
import com.pf.dto.response.UserListResp;
import com.pf.service.UserService;
import com.pf.utils.BaseResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2021/8/27
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询用户列表信息
     *
     * @param userListReq
     * @return
     */
    @GetMapping("/page/list")
    public BaseResult<PageBaseResp<UserListResp>> getUserPageList(UserListReq userListReq) {
        return BaseResultUtils.success(userService.getUserPageList(userListReq));
    }

    /**
     * 新增用户
     *
     * @param userReq
     * @return
     */
    @PostMapping("/add")
    public BaseResult addUser(@RequestBody @Valid UserAddReq userReq) {
        userService.addUser(userReq);
        return BaseResultUtils.success();
    }

    /**
     * 修改用户
     *
     * @param userReq
     * @return
     */
    @PostMapping("/update")
    public BaseResult updateUser(@RequestBody @Valid UserUpdReq userReq) {
        userService.updateUser(userReq);
        return BaseResultUtils.success();
    }

}
